//
//  FKHomeCouponCell.m
//  WanTao
//
//  Created by Macbook Pro on 2019/4/20.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKHomeCouponCell.h"
#import "FKHomeCoupon.h"

@interface FKHomeCouponCell ()

@property (nonatomic, weak) UILabel *priceLabel;
@property (nonatomic, weak) UILabel *conditionLabel;
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *timeLabel;

@end

@implementation FKHomeCouponCell

- (void)setupSubviews
{
    [super setupSubviews];
    self.backgroundColor = [UIColor clearColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"coupon_home_cell_bg"]];
    [self.contentView addSubview:bgView];
    
    UILabel *priceLabel = [UILabel fk_labelWithFont:fk_adjustFont(20) textColor:fkMainColor];
    [self.contentView addSubview:priceLabel];
    self.priceLabel = priceLabel;
    
    UILabel *conditionLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor333333];
    [self.contentView addSubview:conditionLabel];
    self.conditionLabel = conditionLabel;
    
    UILabel *titleLabel = [UILabel fk_labelWithFont:fk_adjustFont(13) textColor:fkColor333333];
    [self.contentView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    UILabel *timeLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor999999];
    [self.contentView addSubview:timeLabel];
    self.timeLabel = timeLabel;
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(fk_adjustW(8));
        make.width.offset(fk_adjustW(72));
        make.top.offset(fk_adjustW(20));
    }];
    [conditionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.equalTo(priceLabel);
        make.bottom.offset(fk_adjustW(-20));
    }];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(fk_adjustW(100));
        make.top.equalTo(priceLabel);
    }];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel);
        make.centerY.equalTo(conditionLabel);
    }];
}

- (void)setData:(id)data
{
    [super setData:data];
    
    if ([data isKindOfClass:[FKHomeCoupon class]]) {
        FKHomeCoupon *model = (FKHomeCoupon *)data;
        self.priceLabel.attributedText = model.priceStr;
        self.conditionLabel.text = model.condition;
        self.titleLabel.text = model.title;
        self.timeLabel.text = model.timeStr;
    }
}

@end
